@layerzerolabs/lz-definitions
The LayerZero Definitions package provides a comprehensive set of type definitions and utilities for interacting with various blockchains. It includes enums, types, and interfaces that facilitate the development and integration of applications with the LayerZero protocol.
Features
- Enums: Provides a set of enums representing various blockchain-related constants.
- Types: Defines various types used across the LayerZero protocol.
- Interfaces: Provides interfaces for different blockchain specifications and configurations.
- Utilities: Includes utility functions for converting and handling blockchain-related data.
Installation
To install the LayerZero Definitions package, you can use npm or yarn:
npm install @layerzerolabs/lz-definitions
or
yarn add @layerzerolabs/lz-definitions
Utilities
networkToEndpointId
import {
networkToEndpointId,
EndpointVersion,
EndpointId,
} from "@layerzerolabs/lz-definitions";
const endpointId: EndpointId = networkToEndpointId(
"ethereum-mainnet",
EndpointVersion.V1,
);
console.log(endpointId);
networkToEnv
import {
networkToEnv,
EndpointVersion,
Environment,
} from "@layerzerolabs/lz-definitions";
const environment: Environment = networkToEnv(
"ethereum-mainnet",
EndpointVersion.V1,
);
console.log(environment);
networkToStage
import { networkToStage, Stage } from "@layerzerolabs/lz-definitions";
const stage: Stage = networkToStage("ethereum-mainnet");
console.log(stage);
endpointIdToNetwork
import {
endpointIdToNetwork,
Environment,
Network,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const network: Network = endpointIdToNetwork(
SandboxV2EndpointId.APTOS_V2_SANDBOX,
Environment.MAINNET,
);
console.log(network);
endpointIdToVersion
import {
endpointIdToVersion,
EndpointVersion,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const version: EndpointVersion = endpointIdToVersion(
SandboxV2EndpointId.APTOS_V2_SANDBOX,
);
console.log(version);
endpointIdToChainKey
import {
endpointIdToChainKey,
ChainKey,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const chainKey: ChainKey = endpointIdToChainKey(
SandboxV2EndpointId.APTOS_V2_SANDBOX,
);
console.log(chainKey);
chainAndStageToEndpointId
import {
chainAndStageToEndpointId,
Chain,
Stage,
EndpointVersion,
EndpointId,
} from "@layerzerolabs/lz-definitions";
const endpointId: EndpointId = chainAndStageToEndpointId(
Chain.ETHEREUM,
Stage.MAINNET,
EndpointVersion.V1,
);
console.log(endpointId);
chainAndStageToNetwork
import {
chainAndStageToNetwork,
Chain,
Stage,
Network,
} from "@layerzerolabs/lz-definitions";
const network: Network = chainAndStageToNetwork(Chain.ETHEREUM, Stage.MAINNET);
console.log(network);
endpointSpecToNetwork
import {
endpointSpecToNetwork,
EndpointSpec,
Network,
} from "@layerzerolabs/lz-definitions";
const spec: EndpointSpec = {
chain: Chain.ETHEREUM,
stage: Stage.MAINNET,
version: EndpointVersion.V1,
env: Environment.MAINNET,
};
const network: Network = endpointSpecToNetwork(spec);
console.log(network);
endpointSpecToEnv
import {
endpointSpecToEnv,
EndpointSpec,
Environment,
} from "@layerzerolabs/lz-definitions";
const spec: EndpointSpec = {
chain: Chain.ETHEREUM,
stage: Stage.MAINNET,
version: EndpointVersion.V1,
env: Environment.MAINNET,
};
const environment: Environment = endpointSpecToEnv(spec);
console.log(environment);
endpointSpecToEndpointId
import {
endpointSpecToEndpointId,
EndpointSpec,
EndpointId,
} from "@layerzerolabs/lz-definitions";
const spec: EndpointSpec = {
chain: Chain.ETHEREUM,
stage: Stage.MAINNET,
version: EndpointVersion.V1,
env: Environment.MAINNET,
};
const endpointId: EndpointId = endpointSpecToEndpointId(spec);
console.log(endpointId);
endpointIdToEndpointSpec
import {
endpointIdToEndpointSpec,
EndpointId,
EndpointSpec,
Environment,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const spec: EndpointSpec = endpointIdToEndpointSpec(
SandboxV2EndpointId.APTOS_V2_SANDBOX,
Environment.MAINNET,
);
console.log(spec);
networkToChain
import { networkToChain, Chain } from "@layerzerolabs/lz-definitions";
const chain: Chain = networkToChain("ethereum-mainnet");
console.log(chain);
networkToChainType
import { networkToChainType, ChainType } from "@layerzerolabs/lz-definitions";
const chainType: ChainType = networkToChainType("ethereum-mainnet");
console.log(chainType);
chainToChainType
import {
chainToChainType,
Chain,
ChainType,
} from "@layerzerolabs/lz-definitions";
const chainType: ChainType = chainToChainType(Chain.ETHEREUM);
console.log(chainType);
endpointIdToChain
import {
endpointIdToChain,
Chain,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const chain: Chain = endpointIdToChain(SandboxV2EndpointId.APTOS_V2_SANDBOX);
console.log(chain);
endpointIdToStage
import {
endpointIdToStage,
Stage,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const stage: Stage = endpointIdToStage(SandboxV2EndpointId.APTOS_V2_SANDBOX);
console.log(stage);
endpointIdToChainType
import {
endpointIdToChainType,
ChainType,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const chainType: ChainType = endpointIdToChainType(
SandboxV2EndpointId.APTOS_V2_SANDBOX,
);
console.log(chainType);
getNetworksForStage
import { getNetworksForStage, Stage } from "@layerzerolabs/lz-definitions";
const networks: string[] = getNetworksForStage(Stage.MAINNET);
console.log(networks);
getChainIdForNetwork
import { getChainIdForNetwork } from "@layerzerolabs/lz-definitions";
const chainId: string = getChainIdForNetwork("ethereum", "mainnet", "1.0.0");
console.log(chainId);
getNetworkForChainId
import {
getNetworkForChainId,
Chain,
Stage,
SandboxV2EndpointId,
} from "@layerzerolabs/lz-definitions";
const networkInfo = getNetworkForChainId(SandboxV2EndpointId.APTOS_V2_SANDBOX);
console.log(networkInfo.chainName, networkInfo.env, networkInfo.ulnVersion);
isNetworkEndpointIdSupported
import {
isNetworkEndpointIdSupported,
EndpointVersion,
} from "@layerzerolabs/lz-definitions";
const isSupported: boolean = isNetworkEndpointIdSupported(
"ethereum-mainnet",
EndpointVersion.V1,
);
console.log(isSupported);
isEvmChain
import { isEvmChain, Chain } from "@layerzerolabs/lz-definitions";
const isEvm: boolean = isEvmChain(Chain.ETHEREUM);
console.log(isEvm);